//
//  RTTabBarController.m
//  WeiboSina
//
//  Created by Brisinga on 16/3/4.
//  Copyright © 2016年 Root. All rights reserved.
//

#import "RTTabBarController.h"
#import "RTNavigationController.h"
#import "RTHomeViewController.h"
#import "RTMessageViewController.h"
#import "RTDiscoverViewController.h"
#import "RTProfileViewController.h"
#import "RTTabBar.h"

@interface RTTabBarController ()

@end

@implementation RTTabBarController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    // 初始化
    [self setupUI];
}


#pragma mark - 初始化内部控件
- (void)setupUI {

    // 添加Home控制器
    [self addChildViewController:[[RTHomeViewController alloc] init] imageName:@"tabbar_home" title:@"首页"];
    
    // 添加Message控制器
    [self addChildViewController:[[RTMessageViewController alloc] init] imageName:@"tabbar_message_center" title:@"消息"];
    
    // 添加Discover控制器
    [self addChildViewController:[[RTDiscoverViewController alloc] init] imageName:@"tabbar_discover" title:@"发现"];
    
    // 添加Profile控制器
    [self addChildViewController:[[RTProfileViewController alloc] init] imageName:@"tabbar_profile" title:@"我"];
    
    // 使用自定义tabBar
    RTTabBar *tabBar = [[RTTabBar alloc] init];
    [self setValue:tabBar forKeyPath:@"TabBar"];
    
    __weak typeof(self)wself = self;
    tabBar.composeBtnClick = ^{
        
        NSLog(@"哈啊 我要弹出控制器%@",wself);
    };
}



#pragma mark - 添加子控制器
- (void)addChildViewController:(UIViewController *)childController imageName:(NSString *)imageName title:(NSString *)title {
    
    // 设置图标
    childController.tabBarItem.image = [UIImage imageNamed:imageName];
    
    // 选中的图片
    UIImage *image = [[UIImage imageNamed:[NSString stringWithFormat:@"%@_selected",imageName]] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    childController.tabBarItem.selectedImage = image;
    
    
    // 设置文字
    childController.title = title;
    
    NSDictionary *fontInfo = @{NSFontAttributeName:[UIFont systemFontOfSize:12]};
    NSDictionary *textColor = @{NSForegroundColorAttributeName:[UIColor orangeColor]};
    
    [childController.tabBarItem setTitleTextAttributes:fontInfo forState:UIControlStateNormal];
    [childController.tabBarItem setTitleTextAttributes:textColor forState:UIControlStateSelected];

    
    // 添加控制器
    RTNavigationController *nav = [[RTNavigationController alloc] initWithRootViewController:childController];
    
    [self addChildViewController:nav];
    
    
}


@end
